using System;
using System.Data;
using System.Reflection;

public class DataRowMapper
{
    public static T MapDataRowToObject<T>(DataRow row) where T : new()
    {
        if (row == null)
            throw new ArgumentNullException(nameof(row));

        T obj = new T();
        Type objType = typeof(T);

        foreach (DataColumn column in row.Table.Columns)
        {
            PropertyInfo property = objType.GetProperty(column.ColumnName, BindingFlags.Public | BindingFlags.Instance);
            if (property != null && property.CanWrite)
            {
                object value = row[column.ColumnName];
                if (value != DBNull.Value)
                {
                    property.SetValue(obj, Convert.ChangeType(value, property.PropertyType), null);
                }
            }
        }

        return obj;
    }
}
